package com.fancymusic.service.impl;

import com.fancymusic.dao.IMusicDao;
import com.fancymusic.dao.IRecMusicDao;
import com.fancymusic.entity.BaseResult;
import com.fancymusic.entity.Music;
import com.fancymusic.entity.RecMusic;
import com.fancymusic.service.IMusicService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class MusicServiceImpl implements IMusicService {

    @Autowired
    IMusicDao iMusicDao;
    @Autowired
    IRecMusicDao iRecMusicDao;

    @Override
    public PageInfo<Music> getAllMusic(Integer pageSize, Integer pageNum) {



        PageHelper.startPage(pageNum, pageSize);
//        int start = pageSize*(pageNum-1);
//        List<Music> allMusic = iMusicDao.getAllMusic(start, pageSize);
        List<Music> allMusic = iMusicDao.getAllMusic();

        PageInfo<Music> pageInfo = new PageInfo<>(allMusic);


        return pageInfo;
    }


    public List<RecMusic> getAllMusic() {
        return iRecMusicDao.getAllMusic();
    }

    @Override
    public Music getMusicByMid(Integer mid) {
        return iMusicDao.getMusicByMid(mid);
    }

    @Override
    public Music save(Music music) {

        BaseResult<String> baseResult = new BaseResult();
        Music s = music;
        System.out.println(s);

//        Music save(@Param("musicName")String musicName,@Param("typeId")Integer typeId);


        iMusicDao.save(music.getMusicName(),music.getMusicType().getMusicId(),music.getSinger().getSingerId());


        return s;
    }

    @Override
    public void deleteMusic(Integer id) {
        iMusicDao.deleteMusic(id);
    }
}
